﻿using Easy.Domain.Test.Models;
using Easy.Domain.Test.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Easy.Domain.Test.Service
{
    public class BlogService
    {
        IBlogRepository _blogRepository;
        public BlogService(IBlogRepository blogRepository)
        {
            _blogRepository = blogRepository;
        }

        public Blog FindById(int id)
        {
            return _blogRepository.FindById(id);
        }

        public void UpdateBlog(Blog blog)
        {
            _blogRepository.Update(blog);

            _blogRepository.UnitOfWork.Commit();
        }

        public void UpdateBlogAs1(Blog blog)
        {
            _blogRepository.Update(blog, a => new { a.Age, a.Name });

            _blogRepository.UnitOfWork.Commit();
        }

        public void AddBlog(Blog blog)
        {
            _blogRepository.Add(blog);
            _blogRepository.UnitOfWork.Commit();
        }

        public void Merge(Blog blog1, Blog blog2)
        {
            _blogRepository.Cover(blog1, blog2);

            _blogRepository.UnitOfWork.Commit();
        }
    }
}
